package linker.plugin;

import java.awt.GridLayout;
import java.net.Authenticator;
import java.net.PasswordAuthentication;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class HttpBasicAuthe extends Authenticator {
	protected PasswordAuthentication getPasswordAuthentication() {
		JTextField username = new JTextField();
		JTextField password = new JPasswordField();
		JPanel panel = new JPanel(new GridLayout(2, 2));
		panel.add(new JLabel("User Name"));
		panel.add(username);
		panel.add(new JLabel("Password"));
		panel.add(password);
		int option = JOptionPane.showConfirmDialog(null, new Object[] {
				"Site: ", getRequestingHost(), "Realm: ",
				getRequestingPrompt(), panel }, "Enter Network Password",
				JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
		if (option == JOptionPane.OK_OPTION) {
			String user = username.getText();
			char pass[] = password.getText().toCharArray();
			return new PasswordAuthentication(user, pass);
		} else {
			return null;
		}
	}

}
